<#include "../base.ftl"/>
<#macro cssfile>
</#macro>

<#macro scriptfile>
</#macro>

<#macro breadcrumb>
    <ul class="breadcrumb">
     <#include "../crumb.ftl"/>
     <li class="active">船舶证书</li>
    </ul>
</#macro>

<#macro title>
广大物流云平台
</#macro>

<#macro jsscript>
   var setting = {
        async: {
            enable: true,
            url: '${request.contextPath}/admin/shipTree.action',
            datatype : 'json',
            autoParam:["id","name","pId"]
        },
        data: {
            simpleData: {
                   enable: true
            }
        },
        callback:{
         onNodeCreated  : zTreeonNodeCreated,
            onClick:zTreeClick
        }
        
    };
    function fillCategoryId(params,postdata){
       var treeObj=$.fn.zTree.getZTreeObj("categoryTree");
       var nodes=  treeObj.getSelectedNodes();
       var add_data=new Object();
       var a=nodes[0].id;
    //alert(a);
       a=a.replace("B","");
       add_data["shippingId"]=a;
       add_data["beanName"] = "tsm.TsmShippingCer";
       add_data["creType"] = "0";
       return add_data;
   }
    
    function zTreeClick(event,treeId,treeNode){
        var a=treeNode.id;
        a=a.replace("B","");
       // alert(a);
        jQuery("#gridTable").jqGrid('setGridParam',{
            url : "${request.contextPath}/list!list.action?shippingId="+a,
            page : 1 
        });
        jQuery("#gridTable").trigger('reloadGrid');
    }
    function zTreeonNodeCreated(event, treeId, treeNode){
        var treeObj = $.fn.zTree.getZTreeObj(treeId);
        //treeObj.expandNode(treeNode, true, true, true);
        var list = treeObj.getNodeByParam("level",'0');
        treeObj.expandNode(list, true, false, true); 

    }

    jQuery(document).ready(function(){
        $.fn.zTree.init($("#categoryTree"), setting);
    });
    
$(function(){
    $("#gridTable").jqGrid({
        //list表格数据获取地址
        url:'${request.contextPath}/list!list.action',
        //list表格编辑地址
        editurl :'${request.contextPath}/operator.action',
        datatype: "json",
        mtype:"POST",
        height: 200,
        colNames:['证书ID','船舶ID','证书代码','证书名','开始日期','结束日期','备注','证书类型','状态','创建人','创建日期','最后修改人','最后修改时间','文件'],
        colModel:[
                    {name:'cerId',jsonmap:'CER_ID',editable:false,hidden:true,editrules:{edithidden:true,required:false}},
                    {name:'shippingId',jsonmap:'SHIPPING_ID',editable:false,editrules:{edithidden:true,required:false},hidden:true},
                    {name:'cerCode',jsonmap:'CER_CODE',editable:true,editrules:{required:true,number:true}},
                    
                    {name:'cerName',jsonmap:'CER_NAME',editable:true,editrules:{required:true}},
                    
                    {name:'startDate', classes:'qqqqq',jsonmap:'START_DATE',editable:true,editrules:{required:true,data:true},
                           editoptions :  {dataInit: function(element) {
                            $(element).datepicker({
                            changeMonth : true,
                            changeYear : true,
                            dateFormat : 'yy-mm-dd',
                            onClose: function(selectedDate){
                            var   today=new   Date(selectedDate);       
                            var   yesterday_milliseconds=today.getTime()+1000*60*60*24;      
                            var   yesterday=new   Date();      
                            yesterday.setTime(yesterday_milliseconds);      
                            var strYear=yesterday.getFullYear();   
                            var strDay=yesterday.getDate();   
                            var strMonth=yesterday.getMonth()+1;   
                            if(strMonth<10)
                                        {   
                                strMonth="0"+strMonth;   
                                     }   
                              var strYesterday=strYear+"-"+strMonth+"-"+strDay;   
                             
                            $("#endDate").datepicker("option","minDate",strYesterday);
                            }
                            });
                        }}               
                    },
                    {name:'endDate',classes:'aaaaa',jsonmap:'END_DATE',editable:true,editrules:{required:true},
                              editoptions :  {dataInit: function(element) {
                            $(element).datepicker({
                            changeMonth : true,
                            changeYear : true,
                            dateFormat : 'yy-mm-dd',
                            onClose: function(selectedDate){
                            var   today=new   Date(selectedDate);       
                            var   yesterday_milliseconds=today.getTime()+1000*60*60*24;      
                            var   yesterday=new   Date();      
                            yesterday.setTime(yesterday_milliseconds);      
           
                            var strYear=yesterday.getFullYear();   
                            var strDay=yesterday.getDate();   
                            var strMonth=yesterday.getMonth()+1;   
                            if(strMonth<10)   
                                        {   
                                strMonth="0"+strMonth;   
                                     }   
                              var strYesterday=strYear+"-"+strMonth+"-"+strDay;   
                            $("#startDate").datepicker("option","maxDate",strYesterday);
                            }
                            });
                        }}       
                    },
                    {name:'remark',jsonmap:'REMARK',editable:true,editrules:{edithidden:true,required:true},hidden:true},
                    {name:'creType',jsonmap:'CRE_TYPE',editable:false,edittype:'select',align:'center',editrules:{required:true},editoptions:{value:{0:'普通证书',1:'保险证书'}},hidden:true},
                    {name:'status',jsonmap:'STATUS',editable:false,edittype:'select',align:'center',editrules:{required:true},editoptions:{value:{0:'有效',1:'无效'}},hidden:true},
                    {name:'createdBy',jsonmap:'CREATED_BY',editable:false,editrules:{required:true},hidden:true},
                    {name:'createdDate',jsonmap:'CREATED_DATE',editable:false,hidden:true,editrules:{required:true},
                        editoptions :  {dataInit: function(element) {
                            $(element).datepicker({changeMonth : true,changeYear : true,dateFormat : 'yy-mm-dd'});
                        }}       
                    },
                    {name:'lastUpdBy',jsonmap:'LAST_UPD_BY',editable:false,editrules:{required:true},hidden:true},
                    {name:'lastUpdDate',jsonmap:'LAST_UPD_DATE',editable:false,hidden:true,editrules:{required:true},
                      editoptions :  {dataInit: function(element) {
                            $(element).datepicker({changeMonth : true,changeYear : true,dateFormat : 'yy-mm-dd'});
                        }}  
                    },
                    {name:'fileUrl',jsonmap:'FILE_URL',editable:false,hidden:true,editrules:{required:true}},
                    //{name:'gu',index:'index1',label:'更新',align:'center',}
                    
                    ],
        sortname : 'CER_ID',
        sortorder : 'ASC',
        viewrecords : true,
        gridview : true,
        autowidth : true,
        rownumbers : true,
        gridComplete: function () {
            var graduateIds = jQuery("#gridTable").jqGrid('getDataIDs');
            for (var i = 0; i < graduateIds.length; i++) {
                var cl = graduateIds[i];
                var link = "<a href='login.jsp?'><font color='red'>下载</font></a>";
                jQuery("#gridTable").jqGrid('setRowData', cl, {file_url: link })
            }
            },
        rowNum : 20,
        rowList : [10,20,30],
             
        jsonReader : {
            page : "page.pageNo", //固定名称
            total : "page.totalPages", //固定名称
            records : "page.totalCount", //固定名称
            root : "page.result", //固定名称
            repeatitems : false, //固定
            id : 'CER_ID'
        },  
        prmNames : {
            rows : "page.pageSize",
            page : "page.pageNo",
            sort : "page.orderBy",
            order : "page.order"
        },
        loadBeforeSend : function(xhr,settings){
            //设置访问的list标签
            settings.data=settings.data+ "&gridKey=/list#TsmShippingCer";
            return true;
        },
        pager : "#gridPager",
        caption : "船舶证书列表"
        }).navGrid('#gridPager', {
                edit : true,
                add : true, 
                del : true,
                search : false
        }, {  
                //edit
           //bSubmit: "Submit",
           //function(){
             // $("#FrmGrid_gridTable").attr("action","${request.contextPath}/admin/getShipManagementList!uploadFile.action");
              //$("#FrmGrid_gridTable").attr("method","post");
               //$("#FrmGrid_gridTable").attr("onsubmit","return:true");
              //$("#FrmGrid_gridTable").attr("enctype","multipart/form-data");
              //$("#FrmGrid_gridTable").submit();
            
            //return false;
           //},
           //reloadAfterSubmit : true, 
           beforeSubmit:true,
           reloadAfterSubmit : true, 
           closeAfterEdit : true,  //修改完毕后关闭
           afterComplete : opertaionPrompt, //更新结束后提示信息
           onclickSubmit: fillCategoryId
        }, {
                //add
           reloadAfterSubmit : true,
           closeAfterAdd : true, //新增完毕后关闭
           afterComplete : opertaionPrompt,
           onclickSubmit: fillCategoryId
       },{
       //del
           reloadAfterSubmit : true, 
           closeAfterEdit : true,  //修改完毕后关闭
           afterComplete : opertaionPrompt, //更新结束后提示信息
           onclickSubmit: fillCategoryId        
       }).navButtonAdd('#gridPager',{
           caption:"上传",
           buttonicon:"ui-icon-add", 
           onClickButton: uploadFile
       
   });
   })
   
  function uploadFile(data){
       var fileUploadDiv = $('#fileUploaddiv');
       fileUploadDiv.dialog("option","title","文件上传").dialog("open");
  }
 $("#fileUploaddiv").dialog({  
         autoOpen: false,      
         modal: true,    // 设置对话框为模态（modal）对话框  
         resizable: true,      
         width: 480,  
         open : function(){
         $('#file_upload').uploadify({
            'buttonText'    :   '选择文件',  //上传文件按钮名称
            'multi'         :   false,  //每次是否只能上传一个文件
            'swf'      : '${request.contextPath}/libs/jqgrid/css/uploadify.swf',
            'uploader' :  '${request.contextPath}/servlet/upload;jsessionid=<%=session.getId()%>',//文件上窜URL，固定URL
            'auto'          :   true,  //文件是否自动上传
            'uploadLimit': 9,//上传文件最大个数
            'onUploadSuccess' : function(file, data, response) {//文件上传成功后回调
                 if(JSON.parse(data).result){
                       alert("操作成功");
                 }else{
                       alert("操作失败");
            
               }
        
    } ,
    'onUploadStart' :   function(file) {  //上传文件前调用，传递参数 beanId必须传，调用那个上传文件的服务实现
        var param={"beanId":"uploadifyServiceImpl"};
        
            
        $("#file_upload").uploadify("settings", "formData",param);  
       
   }  
});
         }
})

$(function(){
$('#file_upload').uploadify({
    'buttonText'    :   '选择文件',  //上传文件按钮名称
    'multi'         :   false,  //每次是否只能上传一个文件
    'swf'      : '${request.contextPath}/libs/jqgrid/css/uploadify.swf',
    'uploader' :  '${request.contextPath}/servlet/upload;jsessionid=<%=session.getId()%>',//文件上窜URL，固定URL
    'auto'          :   true,  //文件是否自动上传
    'uploadLimit': 9,//上传文件最大个数
    'onUploadSuccess' : function(file, data, response) {//文件上传成功后回调
        if(JSON.parse(data).result){
            alert("操作成功");
        }else{
            alert("操作失败");
            
        }
        
    } ,
    'onUploadStart' :   function(file) {  //上传文件前调用，传递参数 beanId必须传，调用那个上传文件的服务实现
        var param={"beanId":"uploadifyServiceImpl"};
        
            
        $("#file_upload").uploadify("settings", "formData",param);  
       
   }  
});
});




</#macro>
<#macro main>
	<div class="leftMaindiv">
	  	<div id="treediv" class="ui-widget-content ui-corner-all">
	   		<ul id="categoryTree" class="ztree"></ul>
	  	</div>
  	</div>
  	<div class="rightdetaildiv">
       	<table id="gridTable"></table>
       	<div id="gridPager"></div>
  	</div>
  	<div id="fileUploadDiv" style="display: none; font-size: 11px;">
	</div>
	 
  <input id="file_upload" name="file_upload" type="file"/>
  <a href="${request.contextPath}/servlet/download?beanId=downLoadFileServiceImpl" class="fileDownloadPromise">Report4.pdf</a>
</#macro>

